package com.example.demo.controller;

import com.example.demo.entity.Vistor;
import com.example.demo.enums.ResultEnum;
import com.example.demo.service.VistorService;
import com.example.demo.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RequestMapping("/vistor")
@RestController
public class VistorController {

    @Autowired
    private VistorService vistorService;

    @RequestMapping("/addConsult")
    public ResultVO addConsult(@RequestParam Map<String,String> map){
        int result = vistorService.addConsult(map);
        return new ResultVO(ResultEnum.SUCCESS,result);
    }


    @RequestMapping("/updateConsult")
    public ResultVO updateConsult(@RequestParam Map<String,String> map){
        int result = vistorService.updateConsult(map);
        return new ResultVO(ResultEnum.SUCCESS,result);
    }

    @RequestMapping("/del1")
    public ResultVO del1(String vid){
        Integer id= Integer.valueOf(vid);
        int result = vistorService.del1(id);
        return new ResultVO(ResultEnum.SUCCESS,result);
    }

    @RequestMapping("/addMask")
    public ResultVO addMask(@RequestParam Map<String,String> map){
        int result = vistorService.addMask(map);
        return new ResultVO(ResultEnum.SUCCESS,result);
    }

    @RequestMapping("/updateMask")
    public ResultVO updateMask(@RequestParam Map<String,String> map){
        int result = vistorService.updateConsult(map);
        return new ResultVO(ResultEnum.SUCCESS,result);
    }
    @RequestMapping("/del2")
    public ResultVO del2(String vid){
        Integer id= Integer.valueOf(vid);
        int result = vistorService.del2(id);
        return new ResultVO(ResultEnum.SUCCESS,result);
    }
    @RequestMapping("/findAllConsult")
    public ResultVO findAllConsult(String startNum,String rows){
        System.out.println(startNum+":"+rows);
        List<Vistor> lists = vistorService.showToPage1(Integer.valueOf(startNum),Integer.valueOf(rows));
        return new ResultVO(ResultEnum.SUCCESS,lists);
    }

    @RequestMapping("/findAllMarks")
    public ResultVO findAllMarks(Integer startNum,Integer rows){
        List<Vistor> lists = vistorService.showToPage2(startNum,rows);
        return new ResultVO(ResultEnum.SUCCESS,lists);
    }

    @RequestMapping("/showToPage1")
    public ResultVO showToPage1(Integer startNum,Integer rows){
        List<Vistor> lists = vistorService.showToPage1(startNum,rows);
        return new ResultVO(ResultEnum.SUCCESS,lists);
    }

    @RequestMapping("/showToPage2")
    public ResultVO showToPage2(Integer startNum,Integer rows){
        List<Vistor> lists = vistorService.showToPage2(startNum,rows);
        return new ResultVO(ResultEnum.SUCCESS,lists);
    }

    @RequestMapping("/findTotal1")
    public ResultVO findTotal1(){
        int result = vistorService.findTotal1();
        return new ResultVO(ResultEnum.SUCCESS,result);
    }

    @RequestMapping("/findTotal2")
    public ResultVO findTotal2(){
        int result = vistorService.findTotal2();
        return new ResultVO(ResultEnum.SUCCESS,result);
    }

}
